import EventActionDefinitions from "./eventActionDefinitions.js"
import useDelegator from "../../utils/handlePlatform/UseDelegator.js"

const { useEffect, useState } = window.React
const Main = (props) => {
  const [number, setNumber] = useState(1)
  const customConfig = props?.customConfig
  const initComData = () => {
    customConfig.number && setNumber(customConfig.number)
  }
  const do_EventCenter_message = ({ value }) => {
    alert(value)
  }
  const actionFunDefinitions = {
    do_EventCenter_message
  }
  /**
   * 封装smardaten触发事件的方法
   * @param {String} eventName 事件名
   * @param {Object} payload 事件传参
   * @example triggerEvent("click",{value:"123"})
   *
   */
  const handleClick = () => {
    props.triggerEvent?.("click", { value: "123" })
  }
  useEffect(() => {
    initComData()
  }, [])
  useDelegator(props, actionFunDefinitions, EventActionDefinitions)
  return (
    <>
      <div>
        {/*以下为样例，正式开发请去除相关代码*/}
        {number}
        <button onClick={handleClick}>逻辑控制事件触发样例</button>
      </div>
    </>
  )
}

export default Main
